using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
	/// <summary>
	/// Strongly-typed collection for the Language class.
	/// </summary>
	[Serializable]
	public partial class LanguageCollection : ActiveList<Language,LanguageCollection> 
	{	   
		public LanguageCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Language table.
	/// </summary>
	[Serializable]
	public partial class Language : ActiveRecord<Language>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Language()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Language(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public Language(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Language(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Language", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarLanguageID = new TableSchema.TableColumn(schema);
				colvarLanguageID.ColumnName = "LanguageID";
				colvarLanguageID.DataType = DbType.Guid;
				colvarLanguageID.MaxLength = 0;
				colvarLanguageID.AutoIncrement = false;
				colvarLanguageID.IsNullable = false;
				colvarLanguageID.IsPrimaryKey = true;
				colvarLanguageID.IsForeignKey = false;
				colvarLanguageID.IsReadOnly = false;
				colvarLanguageID.DefaultSetting = @"";
				colvarLanguageID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLanguageID);
				
				TableSchema.TableColumn colvarCultureName = new TableSchema.TableColumn(schema);
				colvarCultureName.ColumnName = "CultureName";
				colvarCultureName.DataType = DbType.String;
				colvarCultureName.MaxLength = 20;
				colvarCultureName.AutoIncrement = false;
				colvarCultureName.IsNullable = false;
				colvarCultureName.IsPrimaryKey = false;
				colvarCultureName.IsForeignKey = false;
				colvarCultureName.IsReadOnly = false;
				colvarCultureName.DefaultSetting = @"";
				colvarCultureName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCultureName);
				
				TableSchema.TableColumn colvarShortCode = new TableSchema.TableColumn(schema);
				colvarShortCode.ColumnName = "ShortCode";
				colvarShortCode.DataType = DbType.String;
				colvarShortCode.MaxLength = 2;
				colvarShortCode.AutoIncrement = false;
				colvarShortCode.IsNullable = false;
				colvarShortCode.IsPrimaryKey = false;
				colvarShortCode.IsForeignKey = false;
				colvarShortCode.IsReadOnly = false;
				colvarShortCode.DefaultSetting = @"";
				colvarShortCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarShortCode);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Language",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("LanguageID")]
		public Guid LanguageID 
		{
			get { return GetColumnValue<Guid>(Columns.LanguageID); }

			set { SetColumnValue(Columns.LanguageID, value); }

		}

		  
		[XmlAttribute("CultureName")]
		public string CultureName 
		{
			get { return GetColumnValue<string>(Columns.CultureName); }

			set { SetColumnValue(Columns.CultureName, value); }

		}

		  
		[XmlAttribute("ShortCode")]
		public string ShortCode 
		{
			get { return GetColumnValue<string>(Columns.ShortCode); }

			set { SetColumnValue(Columns.ShortCode, value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		private Medianamik.SubsonicDALProvider.DAL.NodePropertyValueCollection colNodePropertyValueRecords;
		public Medianamik.SubsonicDALProvider.DAL.NodePropertyValueCollection NodePropertyValueRecords()
		{
			if(colNodePropertyValueRecords == null)
				colNodePropertyValueRecords = new Medianamik.SubsonicDALProvider.DAL.NodePropertyValueCollection().Where(NodePropertyValue.Columns.LanguageId, LanguageID).Load();
			return colNodePropertyValueRecords;
		}

		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varLanguageID,string varCultureName,string varShortCode)
		{
			Language item = new Language();
			
			item.LanguageID = varLanguageID;
			
			item.CultureName = varCultureName;
			
			item.ShortCode = varShortCode;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varLanguageID,string varCultureName,string varShortCode)
		{
			Language item = new Language();
			
				item.LanguageID = varLanguageID;
			
				item.CultureName = varCultureName;
			
				item.ShortCode = varShortCode;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn LanguageIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn CultureNameColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn ShortCodeColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string LanguageID = @"LanguageID";
			 public static string CultureName = @"CultureName";
			 public static string ShortCode = @"ShortCode";
						
		}

		#endregion
		
		
		
	}

}

